(function ($) {
    /**
     *将表单内容序列化成对象参数形式{key:value,key1:value1...}
     * @returns {}
     */
    $.fn.formData = function () {
        var $form = $(this);
        var serializeArray = $form.serializeArray();
        $form.serializeArray();
        var data = {};
        serializeArray.map(function (v) {
            var name = v.name;
            var value = v.value;
            var datum = data[name];
            if (datum) {
                if (!$.isArray(datum)) {
                    var oldValue = datum;
                    data[name] = new Array();
                    data[name].push(oldValue);
                }
                data[name].push(value);
            } else {
                data[name] = value;
            }
        });
        return data;
    }
    /**
     * 将图表单中的每一行作为一个对象，序列化每一行中的表单元素
     * @returns {Array}
     */
    $.fn.tableSerializeArray = function () {
        var $table = $(this);
        var $trs = $table.find("tr");
        var tableData = [];
        $trs.each(function () {
            var $tr = $(this);
            var $tds = $tr.find("td");
            var trData = {};
            var isHaveData = false;
            $tds.each(function () {
                var $td = $(this);
                var $formElements = $td.find("input,select,textarea");
                $formElements.each(function () {
                    $formElement = $(this);
                    var name = $formElement.attr("name");
                    var value = $formElement.val();
                    if (name) {
                        trData[name] = value;
                        isHaveData = true;
                    }
                })
            });
            if (isHaveData) {
                tableData.push(trData);
            }
        });
        return tableData;
    }
})(jQuery);